package com.topcoder.srm491;

/**
 * Fox Jiro likes dice. He wants to make his own dice. Each die he wants to 
 * make is a cube. Each of the 6 faces has an integer between 1 and N, 
 * inclusive. No two faces have same number. Also the following condition must 
 * be satisfied: for all faces, the sum of the numbers on opposite faces must 
 * be equal and the sum must be greater than or equal to K.
 * 
 * He realized that there are many ways to make such dice. He wants to know 
 * how many ways there are. Please help Jiro to make a program that is given 
 * two integers N and K and returns the number of different dice satisfying 
 * the condition mentioned above.
 * 
 * Two dice are considered the same if you can rotate one to form the other.
 * 
 * [Algorithm] count the solution of i+j=k (i!=j, k>=K, 1<=i, j<=N), then
 * C(s, 3) is solution number for k. 
 */
public class FoxMakingDice {
	public long theCount(int N, int K) {
		long count = 0;
		
		for (int k=K; k<2*N-1; k++) {
			int s = 0;
			for (int i=1; i<N; i++) {
				int j = k - i;
				if (j>i && j<=N) s++;
			}
			
			count += s*(s-1)*(s-2)/3;
		}
		
		return count;
	}
}
